﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Text.RegularExpressions;
using System.Collections;
using System.Xml.Linq;

namespace TanHungViet.Helper
{
    public class Constant
    {
        public const string ParamNameUserAccessedCount = "UserAccessedCount";
        public const string ParamEmailAcc = "EmailAccount";
        public const string ParamEmailPwd = "EmailPassword";

        public const int PageSize = 8;
        public const int PageSize2 = 5;

        public const string ImageFolerContent = @"Content\images_content\";
        public const string ImagePath = "~/Content/images/";
        public const string ImageContentPath = "~/Content/images_content/";
        public const string ImageContentDetailPath = "~/Content/images_content_detail/";

        public const string CodeNoiDungBenTrai = "noi-dung-ben-trai";
        public const string CodeNoiDungThoiGianLamViec = "thoi-gian-lam-viec";
        public const string CodeNoiDungQuangCaoBenPhai = "quang-cao-ben-phai";
        public const string CodeGioiThieu = "gioi-thieu";
        public const string CodeDichVu = "dich-vu";
        public const string CodeBaoGia = "bao-gia";

        public static readonly List<int> IDListDuAn = (new int[3] { 10, 11, 12 }).ToList<int>();
        public const int IDTinTuc = 3;
        public const int IDTuVan = 4;
        public const int IDHoiDap = 6;
        public const int IDBaoGia = 7;
        public const int IDGioiThieu = 1;
        public const int IDDichVu = 2;
        public const int IDLienHe = 9;
        public const int IDTuyenDung = 8;
        public const int IDNoiDungBenTrai = 78;
        public const int IDNoiDungThoiGianLamViec = 79;
        public const int IDNoiDungQuangCaoBenPhai = 80;
    }


    public class Util
    {
        public static string ConvertToUnsignString(string s)
        {
            Regex regex = new Regex(@"\p{IsCombiningDiacriticalMarks}+");
            string strFormD = s.Normalize(NormalizationForm.FormD);

            return regex.Replace(strFormD, String.Empty).Replace('\u0111', 'd').Replace('\u0110', 'D');
        }

        public static string GenerateCodeByTitle(string contentTitle)
        {
            contentTitle = contentTitle.Replace("?", string.Empty);
            contentTitle = contentTitle.Replace(",", string.Empty);
            contentTitle = contentTitle.Replace(":", string.Empty);

            contentTitle = ConvertToUnsignString(contentTitle);
            contentTitle = contentTitle.Trim();
            string[] arrString = contentTitle.Split(new Char[] { ' ' });

            string result = "";
            foreach (string word in arrString)
            {
                result += "-";
                result += word;
            }
            result = result.Substring(1, result.Length - 1);

            return result;
        }

        public static void GetMailInfo(out string userName, out string password)
        {
            string physicPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
            XDocument xDoc = XDocument.Load(physicPath + @"MailInfo.xml");
            XElement xEle = xDoc.Element("MailInfo");

            userName = xEle.Element("UserName").Value;
            password = xEle.Element("Password").Value;
        }
    }


    public class PaginatedList<T> : List<T>
    {
        public int PageIndex { get; private set; }
        public int PageSize { get; private set; }
        public int TotalCount { get; private set; }
        public int TotalPages { get; private set; }

        public PaginatedList(IEnumerable<T> source, int pageIndex, int pageSize)
        {
            PageIndex = pageIndex;
            PageSize = pageSize;
            TotalCount = source.Count();
            TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);

            this.AddRange(source.Skip(PageIndex * PageSize).Take(PageSize));
        }

        public bool HasPreviousPage
        {
            get
            {
                return (PageIndex > 0);
            }
        }

        public bool HasNextPage
        {
            get
            {
                return (PageIndex + 1 < TotalPages);
            }
        }
    }


    public class PaginationHelper
    {
        public static int min_pagesize = 5;

        public static ArrayList GetPageginationSizeList()
        {
            ArrayList arrOpsSize = new ArrayList();
            arrOpsSize.Add(5);
            arrOpsSize.Add(10);
            arrOpsSize.Add(15);
            arrOpsSize.Add(20);

            return arrOpsSize;
        }
    }
}
